// part1:C10:ex10.32.cpp
// use find and accumulate to write bookstore. 
#include <iostream>
#include <iterator>
#include <algorithm>
#include "Sales_data.h"

using namespace std;

int main(int argc, char *argv[])
{
    vector<Sales_data> vs;
    istream_iterator<Sales_data> in_iter(cin);
    istream_iterator<Sales_data> eof;

    while (in_iter != eof) {
      vs.push_back(*in_iter++);
    }
    if (vs.empty()) {
      std::cerr << "No data?!" << std::endl;
      return -1;
    }

    sort(vs.begin(), vs.end(), compareIsbn);
    auto l = vs.begin();
    while (l != vs.end()) {
      auto item = *l;
      auto r = find_if(l + 1, vs.end(),
                       [item](const Sales_data &item1){
                         return item1.isbn() != item.isbn();
                       });
      cout << accumulate(l + 1, r, item) << endl;
      l = r;
    }
    return 0;
}
